"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class User extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
    }
  }
  User.init(
    {
      gender: DataTypes.INTEGER,
      username: DataTypes.STRING,
      username: DataTypes.STRING,
      password: DataTypes.STRING,
      name: DataTypes.STRING,
      stuCode: DataTypes.STRING,
      college: DataTypes.INTEGER,
      major: DataTypes.INTEGER,
      grade: DataTypes.INTEGER,
      role: DataTypes.INTEGER,
      phone: DataTypes.STRING,
      email: DataTypes.STRING,
      society: DataTypes.STRING,
    },
    {
      sequelize,
      modelName: "User",
    }
  );
  User.associate = function (models) {
    models.User.belongsTo(models.College, {
      foreignKey: 'college', 
      targetKey:'id'
    });
    models.User.belongsTo(models.Major, {
      foreignKey: 'major', 
      targetKey:'id'
    });
    models.User.belongsTo(models.Grade, {
      foreignKey: 'grade', 
      targetKey:'id'
    });
    models.User.belongsTo(models.Society, {
      foreignKey: 'id', 
      targetKey:'minister'
    });
  };
  return User;
};
